<?php

namespace App\Admin\Controllers\exam;

use App\Common\statement\CommonStatement;
use App\Models\exams\Exam;
use App\Models\exams\ExamQuestion;
use App\Models\exams\Exams;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ExamQuestionController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '试卷（试题）';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ExamQuestion());

        $grid->model()->where('status',1)->latest();

        $grid->disableExport();
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableView();
            $actions->disableDelete();
            $actions->disableEdit();
        });

        $grid->filter(function ($filter) {
            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            $filter->equal('exam_id',__('试卷id'));

            $filter->column(1 / 2, function ($filter) {
                $filter->like('exam.title', __('Title'));
            });
        });

        $grid->column('id', __('ID'));
        $grid->column('exam.title', __('试卷标题'));
        $grid->column('question.title', __('试题'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));
        $grid->actions(function ($actions) {

        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ExamQuestion::findOrFail($id));



        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ExamQuestion());

        $form->saving(function (Form $form) {

        });

        return $form;
    }
}
